import sys
from PyQt5.QtWidgets import QDialog,QApplication
# from demoMousetrack import *


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(480, 358)
        self.label = QtWidgets.QLabel(Dialog)
        self.label.setGeometry(QtCore.QRect(71, 54, 271, 61))
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(Dialog)
        self.label_2.setGeometry(QtCore.QRect(70, 110, 311, 41))
        self.label_2.setText("")
        self.label_2.setObjectName("label_2")

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)


    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
        self.label.setText(_translate("Dialog", "显示鼠标移动时候的(x,y)坐标的位置"))

        # self.mouse_listen_timer = QtCore.QTimer(Dialog)
        # self.mouse_listen_timer.timeout.connect(self.print_mouse)
        # self.mouse_listen_timer.start(1000)

    # def print_mouse(self):
    #     # print(self.mouse.get_mouse_pos())
    #     s = event.windowPos()
    #     print('globle:',event.globalPos())
    #     self.setMouseTracking(True)
    #     print('X:' + str(s.x()))
    #     print('Y:' + str(s.y()))

class MyForm(QDialog):
    def __init__(self):
        super().__init__()
        self.ui = Ui_Dialog()
        self.setMouseTracking(True)
        self.ui.setupUi(self)
        self.show()
    def mouseMoveEvent(self,event):
        x = event.x()
        y = event.y()
        text = "x:{0},y:{1}".format(x,y)
        print('globle:',event.globalPos())
        self.ui.label_2.setText(text)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    w = MyForm()
    w.show()
    sys.exit(app.exec_())
